"""
组合生成器模块
"""

from typing import List, Dict, Any, Iterator
from .config import CONFIG


class CombinationGenerator:
    """预处理组合生成器类"""
    
    def __init__(self):
        """初始化组合生成器"""
        self.smoothing_methods = ['sg', 'none']
        self.derivative_orders = [0, 1, 2]
        self.baseline_methods = ['msc', 'snv', 'none']
    
    def generate_combinations(self) -> List[Dict[str, Any]]:
        """
        生成所有预处理组合
        
        Returns:
            List[Dict[str, Any]]: 所有预处理组合的列表
        """
        combinations = []
        
        for smoothing in self.smoothing_methods:
            for derivative in self.derivative_orders:
                for baseline in self.baseline_methods:
                    combination = {
                        'smoothing': smoothing,
                        'derivative': derivative,
                        'baseline': baseline,
                        'name': self.get_combination_name({
                            'smoothing': smoothing,
                            'derivative': derivative,
                            'baseline': baseline
                        })
                    }
                    combinations.append(combination)
        
        return combinations
    
    def get_combination_name(self, combination: Dict[str, Any]) -> str:
        """
        获取组合的描述性名称
        
        Args:
            combination: 预处理组合参数
            
        Returns:
            str: 组合名称
        """
        smoothing = combination['smoothing']
        derivative = combination['derivative']
        baseline = combination['baseline']
        
        # 使用配置中的映射
        key = (smoothing, derivative, baseline)
        if key in CONFIG['output_suffix_map']:
            return CONFIG['output_suffix_map'][key]
        
        # 如果映射中没有，则生成默认名称
        deriv_name = {0: 'none', 1: '1st', 2: '2nd'}[derivative]
        return f"{smoothing}_{deriv_name}_{baseline}"
    
    def __iter__(self) -> Iterator[Dict[str, Any]]:
        """
        实现迭代器接口
        
        Returns:
            Iterator[Dict[str, Any]]: 组合迭代器
        """
        return iter(self.generate_combinations())